// pages/my_follow/index.js
import api from '../../utils/api'
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast'
import { debounce } from '../../utils/util'
import dayjs from '../../miniprogram_npm/dayjs/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageBaseURL: getApp().imageBaseURL,
    imageResizeParams: getApp().imageResizeParams,
    list:[]
    
  },
  //签到
  navsign(e){
    /*wx.navigateTo({
      url: '/pages/index_active_sign/index?id=' + e.currentTarget.dataset.id
    })*/
    let id = e.currentTarget.dataset.id
    wx.scanCode({
      onlyFromCamera: true,
      success (res) {
        console.log(res)
        let url = '/'+res.path
        let ipos = url.indexOf('scene')
        if( ipos>-1 ){
          let obj = api.decodeurl(url.substr(ipos+6))
          if( !obj['id'] ){
            Toast('二维码格式不正确')
            return
          }
          if( id!=obj['id'] ){
            Toast('活动不匹配')
            return
          }
          url = '/pages/index_active_sign/index?id='+obj['id']
        }else{
          Toast('二维码数据不正确')
          return
        }
        wx.navigateTo({
          url
        })
      }
    })

  },
  navActiveDetail(e){
    wx.navigateTo({
      url: '/pages/index_active_detail/index?id=' + e.currentTarget.dataset.id,
    })
  },
  //撤回报名
  async chehui(e){
    let data={}
    data['flag'] = 'active_chehui'
    data['activeid'] = e.currentTarget.dataset.id
    const {recode, result, message} = await api.send(data)
    if(recode === 'SUCC') {
      Toast.success(message)
      this.getApply()
    }else {
      Toast(message)
    }
  },

  //未评论-去评论页评论 /已评论-去评论页查看评论
  navfeedback(e){
    wx.navigateTo({
      url: '/pages/index_active_evaluation/index?id=' + e.currentTarget.dataset.id
    })
  },
  // 申请列表
  async getApply () {
    let data={}
    data['flag'] = 'hd_passed'
    const {recode, result, message} = await api.send(data)
    if(recode === 'SUCC') {
      this.setData({
        list:result,
      })
    
    }else {
      // Toast(message)
    }
  }, 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getApply()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})